const koa = require('koa')
const next = require('next')
// const router = require('./router')
const Router = require('koa-router')
const Controller = require('./controller')
const middleware = require('./middleware')
const dev = process.env.NODE_ENV !== 'production'
const cors = require('koa2-cors');
const app = next({ dev })
const bodyParser = require('koa-bodyparser')
app.prepare().then(() =>{
    const server = new koa()
    console.log(app)
    //注入中间件
    middleware(server)
    //跨域处理
    server.use(cors())
    //post请求处理
    server.use(bodyParser())
    const router = new Router()
    //注入路由
    server.use(router.routes());

    server.listen(8000, () => {
      console.log('server is running at http://localhost:8000')
    })
})
